package cn.limc.demo.activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.gustavo.hello.R;

import cn.limc.androidcharts.diagram.GridChart;
import cn.limc.androidcharts.series.ChartDataSet;
import cn.limc.androidcharts.series.ChartDataTable;
import cn.limc.androidcharts.series.LineEntity;
import cn.limc.demo.common.BaseActivity;
import cn.limc.demo.controller.MACandleStickChartController;
import cn.limc.demo.controller.StickChartController;

public class TestActivity extends BaseActivity {

    GridChart macandlestickchart;
    MACandleStickChartController stickChartController;
    ChartDataSet stickData;
    ChartDataSet lineData;

    GridChart stickchart;
    StickChartController volController;
    ChartDataSet volStickData;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);


        initData();

        initMACandleStickChart();

        initStickChart();




    }

    private void initData() {
        volStickData = new ChartDataSet(new ChartDataTable(vol));

        lineData = new ChartDataSet();

        // 计算5日均线
        LineEntity ma5 = new LineEntity();
        ma5.setTitle("MA5");
        ma5.setLineColor(Color.WHITE);
        ma5.setTableData(initMA(5));
        lineData.add(ma5);

        // 计算10日均线
        LineEntity ma10 = new LineEntity();
        ma10.setTitle("MA10");
        ma10.setLineColor(Color.CYAN);
        ma10.setTableData(initMA(10));
        lineData.add(ma10);

        // 计算25日均线
        LineEntity ma25 = new LineEntity();
        ma25.setTitle("MA25");
        ma25.setLineColor(Color.BLUE);
        ma25.setTableData(initMA(25));
        lineData.add(ma25);

        stickData = new ChartDataSet(new ChartDataTable(ohlc));

    }

    private void initMACandleStickChart() {
        this.macandlestickchart = (GridChart) findViewById(R.id.maslipcandlestickchart);
        stickChartController = new MACandleStickChartController();
        stickChartController.setStickData(stickData);
        stickChartController.setLineData(lineData);
        stickChartController.applyController(macandlestickchart);




    }

    private void initStickChart() {
        this.stickchart = (GridChart) findViewById(R.id.slipstickchart);
        volController = new StickChartController();
        volController.setStickData(volStickData);
        volController.applyController(stickchart);
    }
}
